package com.bidevalution.controller.api;

import com.bidevalution.business.service.BeSectionParamsService;
import com.qtp.core.model.Response;
import com.qtp.user.models.SysParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 参数抽取控制层
 * 
 * @author shenh@glodon.com
 * @date 2019-05-13 10:28
 */
@RestController
@RequestMapping("/beSectionParams")
public class BeSectionParamsController {

	@Autowired
	private BeSectionParamsService beSectionParamsService;

	/**
	 * 获取评标库中标段的参数信息
	 * 
	 * @param sectionId 标段Id
	 * @param paramCode 参数code
	 * @return
	 */
	@RequestMapping(value = "/getBeSectionParams", method = RequestMethod.GET)
	@ResponseBody
	public Response<String> getBeSectionParams(@RequestParam("sectionId") String sectionId,
			@RequestParam("paramCode") String paramCode) {
		try {
			return Response.ok(beSectionParamsService.getBeSectionParamsByCode(sectionId, paramCode));
		} catch (Exception e) {
			return Response.fail(e.getMessage());
		}
	}

	/**
	 * 获取评标库中标段的参数信息
	 *
	 * @param sectionId 标段Id
	 * @param paramCodes 参数codes 多个逗号分隔
	 * @return
	 */
	@RequestMapping(value = "/getBeSectionParamsByCodes", method = RequestMethod.GET)
	@ResponseBody
	public Response<String> getBeSectionParamsByCodes(@RequestParam("sectionId") String sectionId,
											   @RequestParam("paramCodes") String paramCodes) {
		try {
			return Response.ok(beSectionParamsService.getBeSectionParamsByCodes(sectionId, paramCodes));
		} catch (Exception e) {
			return Response.fail(e.getMessage());
		}
	}

	/**
	 * 新增参数信息
	 * 
	 * @param sectionId 标段Id
	 * @return
	 */
	@RequestMapping(value = "/insertBeSectionParams", method = RequestMethod.POST)
	@ResponseBody
	public Response<Integer> insertBeSectionParams(@RequestParam("sectionId") String sectionId,
			@RequestParam("paramCode") String paramCode, @RequestParam("paramValue") String paramValue) {
		try {
			return Response.ok(beSectionParamsService.insertBeSectionParams(sectionId, paramCode, paramValue));
		} catch (Exception e) {
			return Response.fail(e.getMessage());
		}
	}

	/**
	 * 获取设置的参数
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getSysParams", method = RequestMethod.GET)
	@ResponseBody
	public Response<List<SysParams>> getSysParams(@RequestParam("patpCode") String patpCode) {
		try {
			List<SysParams> sysParams = beSectionParamsService.getSysParams(patpCode);
			if (sysParams != null && sysParams.size() > 0) {
				return Response.ok(sysParams);
			} else {
				return Response.fail("请在后台参数管理中设置参数");
			}
		} catch (Exception e) {
			return Response.fail("获取后台参数失败");
		}
	}

	/**
	 * 获取当前时间
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getSysTime", method = RequestMethod.GET)
	@ResponseBody
	public Response<Long> getSysTime() {
		return Response.ok(System.currentTimeMillis());
	}
}
